package com.quectel.core.module.resource.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.quectel.core.module.device.entity.DeviceCategoryEntity;
import com.quectel.core.module.device.entity.DeviceTypeEntity;
import com.quectel.core.module.resource.entity.ResourceGroupRelationEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author rananxin
 * @date 2021-12-08 16:12:21
 */

public interface ResourceGroupRelationDao extends BaseMapper<ResourceGroupRelationEntity> {
    /**
     * 查询列表
     *
     * @param params
     * @return
     */
    List<ResourceGroupRelationEntity> queryList(Map<String, Object> params);

    /**
     * 查询数量
     *
     * @param params
     * @return
     */
    int queryTotal(Map<String, Object> params);


    /**
     * 根据资源组id获取关联设备种类
     *
     * @param resourceGroupId
     * @return
     */
    @Select("<script>select c.*, rgr.type type from resource_group_relation rgr inner join device_category c on rgr.resource_id = c.id where rgr.resource_group_id = #{resourceGroupId} and rgr.type = 1" +
            "</script>")
    List<DeviceCategoryEntity> findCategoriesByGroupId(@Param("resourceGroupId") Long resourceGroupId);

    /**
     * 根据资源组id获取关联设备类型
     *
     * @param resourceGroupId
     * @return
     */
    @Select("<script>select t.*, rgr.type type from resource_group_relation rgr inner join device_type t on rgr.resource_id = t.id where rgr.resource_group_id = #{resourceGroupId} and rgr.type = 2" +
            "</script>")
    List<DeviceTypeEntity> findTypesByGroupId(@Param("resourceGroupId") Long resourceGroupId);

}
